<template>
  <el-dialog
    title="查看优惠券信息"
    :visible="dialogTableVisible"
    :before-close="handleClose"
  >
    <el-table :data="gridDataList">
      <el-table-column
        align="left"
        property="activityName"
        label="发放活动"
      ></el-table-column>
      <el-table-column label="发放类型" align="left">
        <template slot-scope="scope">
          {{ scope.row.activityType === 0 ? "手动领取" : "" }}
          {{ scope.row.activityType === 1 ? "支付成功后发放" : "" }}
          {{ scope.row.activityType === 2 ? "充值发放" : "" }}
          {{ scope.row.activityType === 4 ? "手动发放" : "" }}
          {{ scope.row.activityType === 5 ? "注册发放" : "" }}
          {{ scope.row.activityType === 6 ? "兑换商品" : "" }}
        </template>
      </el-table-column>
      <el-table-column
        property="couponGetTime"
        label="发放时间"
        align="left"
      ></el-table-column>
      <el-table-column
        property="couponEffectiveTime"
        label="到期时间"
        align="left"
      ></el-table-column>
      <el-table-column
        property="verificationTime"
        label="核销时间"
        align="left"
      ></el-table-column>
      <el-table-column
        align="left"
        property="invalidTime"
        label="作废时间"
      ></el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 20px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="->,total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </el-dialog>
</template>
<script>
import { listByPhone } from "@/api/customer/info";
export default {
  name: "CouponSearch",
  props: {
    dialogTableVisible: {
      type: Boolean,
      default: false,
    },
    couponsInfo: {
      default: () => [],
    },
  },
  data() {
    return {
      // 总条数
      total: 0,
      // 当前在第几页
      pageNum: 1,
      // 一页几条
      pageSize: 10,
      gridDataList: [],
    };
  },
  methods: {
    // 获取列表
    listByPhone() {
      const data = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        mobilePhone: this.couponsInfo.mobilePhone,
      };
      listByPhone(data).then((res) => {
        this.gridDataList = res.rows;
        this.total = res.total;
        console.log("获取数据", res);
      });
    },
    handleClose(done) {
      this.$emit("update:dialogTableVisible", false);
      console.log("关闭了");
      done();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.listByPhone();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.listByPhone();
      console.log(`当前页: ${val}`);
    },
  },
  watch: {
    dialogTableVisible: {
      deep: true, // 深度监听
      handler(newVal, oldVal) {
        if (newVal) {
          this.listByPhone();
          console.log("打开了", this.couponsInfo);
        }
      },
    },
  },
};
</script>
<style scoped lang="scss"></style>
